package com.ui.ajustes;

import java.awt.EventQueue;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JLabel;
import javax.swing.JTextField;

import com.util.Constantes;
import com.util.Escritora;

public class WbAjustes extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	JFileChooser jfc = new JFileChooser();
	private JTextField txtRuta;
	private JTextField txtEducadora;
	private JTextField txtxJardin;
	private JTextField txtClave;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					WbAjustes frame = new WbAjustes();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public WbAjustes() {
		setTitle("Ajustes");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE)
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(btnCancel))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addComponent(tabbedPane, GroupLayout.PREFERRED_SIZE, 217, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
					.addComponent(btnCancel))
		);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("Ajustes", null, panel, null);
		panel.setLayout(null);
		
		JLabel lblCustionario = new JLabel("Custionario");
		lblCustionario.setBounds(10, 11, 54, 14);
		panel.add(lblCustionario);
		
		final JButton btnAbrir = new JButton("abrir...");
		btnAbrir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				FileFilter filtro = new FileNameExtensionFilter("Cuestionarios","srv");
				jfc.setFileFilter(filtro);
				int respuesta = jfc.showOpenDialog(btnAbrir);
			    	if(respuesta == JFileChooser.APPROVE_OPTION){
			    		String rutaA = jfc.getSelectedFile().getAbsolutePath();
			    		txtRuta.setText(rutaA);
			    	}
			}
		});
		btnAbrir.setBounds(261, 7, 89, 23);
		panel.add(btnAbrir);
		
		txtRuta = new JTextField();
		txtRuta.setEditable(false);
		txtRuta.setBounds(74, 8, 177, 20);
		panel.add(txtRuta);
		txtRuta.setColumns(10);
		
		JButton btnGuardar = new JButton("Guardar");
		btnGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				guardarConfiguracion();
			}
		});
		btnGuardar.setBounds(320, 155, 89, 23);
		panel.add(btnGuardar);
		
		JLabel lblEducadora = new JLabel("Educadora:");
		lblEducadora.setBounds(10, 47, 69, 14);
		panel.add(lblEducadora);
		
		JLabel lblJardin = new JLabel("Jardin:");
		lblJardin.setBounds(10, 72, 46, 14);
		panel.add(lblJardin);
		
		JLabel lblClave = new JLabel("Clave:");
		lblClave.setBounds(10, 107, 46, 14);
		panel.add(lblClave);
		
		txtEducadora = new JTextField();
		txtEducadora.setBounds(66, 44, 185, 20);
		panel.add(txtEducadora);
		txtEducadora.setColumns(10);
		
		txtxJardin = new JTextField();
		txtxJardin.setBounds(66, 72, 185, 20);
		panel.add(txtxJardin);
		txtxJardin.setColumns(10);
		
		txtClave = new JTextField();
		txtClave.setBounds(66, 104, 185, 20);
		panel.add(txtClave);
		txtClave.setColumns(10);
		contentPane.setLayout(gl_contentPane);
	}
	
	public void guardarConfiguracion() {
		Escritora es = new Escritora();
		es.escribir(txtRuta.getText(), Constantes.RUTA_DATOS_ESCUELA_Y_EDUCADORA);
		es.escribir(txtEducadora.getText(), Constantes.RUTA_DATOS_ESCUELA_Y_EDUCADORA);
		es.escribir(txtxJardin.getText(), Constantes.RUTA_DATOS_ESCUELA_Y_EDUCADORA);
		es.escribir(txtClave.getText(), Constantes.RUTA_DATOS_ESCUELA_Y_EDUCADORA);
				
		
		
	}

	public static void cargarEncabezado(){
		//String[] datosEnc = lectora.leer(Constantes.RUTA_DATOS_ESCUELA_Y_EDUCADORA).split("\n");
	/*		
		educadora.setText(datosEnc[1]);
		jardin.setText(datosEnc[2]);
		clave.setText(datosEnc[3]);*/
	}

}
